﻿CREATE PROCEDURE [dbo].[UpdateAttachment]
    @AttachmentId uniqueidentifier,
	@Data varbinary(max),
	@Type int,
	@Description nvarchar(max),
    @IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE Attachment

	SET 
	 
	 Data = @Data,
	 [Type] = @Type,
	 [Description] = @Description,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE AttachmentId = @AttachmentId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM Attachment 

	WHERE AttachmentId = @AttachmentId

RETURN 0